$(function() {

    //var log = console.log;

    //for Caching
    var $content = $('#content');

    /*----------------------------------------------------------------------*/
    /* datatable plugin
    /*----------------------------------------------------------------------*/

    $content.find("table.datatable").dataTable({
        "sPaginationType": "two_button",
        "oLanguage": {
            "sLengthMenu": "Prikaži _MENU_ redova po strani",
            "sZeroRecords": "Nema podataka - !",
            "sInfo": "Prikazujem _START_ - _END_ od _TOTAL_ reda",
            "sInfoEmpty": "Prikazujem 0 do 0 od 0 redova",
            "sInfoFiltered": "(filtritam od _MAX_ ukupnih redova)"
        },
        "aoColumnDefs": [ 
        { "bSortable": false, "aTargets": [null,null,null,3] }
        ],
        "iDisplayLength" : "25",
        "aaSorting": [[ 2, "desc" ]] 
    });

    $('.commentstatus').live('click',function(){
        
        var link = this.text;
        var id = this.id 
        var status;

        switch(link){

            case 'Odobri': status = 1; break;
            case 'Blokiraj': status = 0; break;

        }        

        $.ajax({
            type: "POST",
            url: base_url+'comments/commentstatus',
            data: {
                id: id,
                status: status
            },
            dataType: 'json',
            success: function(data){

                if (data.action == true){
                    
                     $('#'+id).parent().parent().fadeOut(900,function(){
                        $(this).remove();
                    });

                    $('.dataTables_info').fadeOut('300');

                }else{

                    alert("Error on server:"+data.msg)

                }


            }
        })

        return false;

    });
})